package com.lys.eduservice.service.impl;

import com.lys.eduservice.cilent.VodClient;
import com.lys.eduservice.entity.EduVideo;
import com.lys.eduservice.mapper.EduVideoMapper;
import com.lys.eduservice.service.EduVideoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 课程视频 服务实现类
 * </p>
 *
 * @author Lyyyys
 * @since 2021-04-30
 */
@Service
public class EduVideoServiceImpl extends ServiceImpl<EduVideoMapper, EduVideo> implements EduVideoService {

    @Autowired
    private EduVideoMapper eduVideoMapper;

    @Autowired
    private VodClient client;

    //根据课程id删除小节
    //TODO删除小节，删除对应的视频文件
    @Override
    public Integer deleteVideoByCourseId(String courseId) {
        List<String> eduVideoList = eduVideoMapper.getVideosByCourseId(courseId);

        //根据多个视频id删除多个视频
        if(eduVideoList.size() > 0){
            client.removeVideoList(eduVideoList);
        }

        Integer result = eduVideoMapper.deleteVideoByCourseId(courseId);
        return result;
    }
}
